﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DownloadFiles
{
    public partial class MDIParent : Form
    {
        private int childFormNumber = 0;

        DataTable dt = new DataTable();

        private void AddColumn(DataColumn dataColumn, bool hide = false)
        {
            dt.Columns.Add(dataColumn);
            dataGridView.Columns.Add(new DataGridViewTextBoxColumn()
            {
                HeaderText = dataColumn.Caption,
                DataPropertyName = dataColumn.ColumnName,
            });
        }

        void Init()
        {

            AddColumn(new DataColumn("Id")
            {
                Caption = "编号",
                DataType = typeof(int),
                AutoIncrement = true,
                AutoIncrementSeed = 1,
                AllowDBNull = false,
                AutoIncrementStep = 1,
            });

            AddColumn(new DataColumn("Url")
            {
                Caption = "待下载文件",
                AllowDBNull = false,
                DataType = typeof(string)
            });
            AddColumn(new DataColumn("SavePath")
            {
                Caption = "文件保存路径",
                AllowDBNull = false,
                DataType = typeof(string)
            });
            AddColumn(new DataColumn("State")
            {
                Caption = "下载状态",
                AllowDBNull = false,
                DataType = typeof(string)
            });
            dt.Rows.Add(null, "test", "", "");
            dt.Rows.Add(null, "2", "", "");
            dt.Rows.Add(null, "3", "", "");
            dataGridView.AutoGenerateColumns = false;
            dataGridView.DataSource = dt;

            //row.SetField("","");
        }
        public MDIParent()
        {
            InitializeComponent();
            Init();
        }

        private void ShowNewForm(object sender, EventArgs e)
        {
            Form childForm = new Form();
            childForm.MdiParent = this;
            childForm.Text = "窗口 " + childFormNumber++;
            childForm.Show();
        }

        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = openFileDialog.FileName;
            }
        }

        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            saveFileDialog.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = saveFileDialog.FileName;
            }
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CutToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void ToolBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }
    }
}
